<template>
  <view>
    <button @click="loginHandler">登录</button>
  </view>
</template>
    
<script lang="ts" setup>
import { login } from "@/api/user";

import { ref, onMounted } from "vue";
const loginHandler = () => {
  uni.login({
    provider: "weixin", //使用微信登录
    success: function (loginRes) {
      uni.getUserInfo({
        provider: "weixin",
        success: function (infoRes) {
          login({
            code: loginRes.code,
            ...infoRes.userInfo,
          }).then((logRes: any) => {
            if (logRes.code === "200") {
              console.log("登录信息", logRes);

              uni.setStorageSync("userInfo", logRes.data);
              uni.setStorageSync("token", logRes.token);
              uni.switchTab({
                url: "/pages/my/index",
              });
            }
          });
        },
      });
    },
  });
};

// 发送消息给服务器
const send = () => {};
onMounted(() => {
  uni.connectSocket({
    url: "wss://192.168.0.111:3001",
  }).then(res=>{
    console.log(res);
    
  })
  // console.log("socket", socket);

  // socket.onOpen(() => {
  //   console.log("WebSocket connected");
  // });
});
</script>
  
  <style>
</style>